package com.ccs.testcase;

import java.util.concurrent.TimeUnit;

import org.junit.Test;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.runners.MethodSorters;
import org.openqa.selenium.WebDriver;

import com.ccs.functions.*;
import com.ccs.loas.*;

@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class Loa_Disapproved {
	private static String loa_number;
	private static WebDriver driver;
	@SuppressWarnings("unused")
	private static String pin;
	
	static
	Webdriver d = new Webdriver();
	@BeforeClass
	public static void startBrowser()throws Exception{
		driver = d.startUp();
	}
	
	@Test
	public void a_login() throws Exception{
		System.out.println("Start Test: LOGIN");
		Login in = new Login();
		in.app(driver);
		System.out.println("End Test: LOGIN\n");
	}
	@Test
	public void b_create_loa() throws Exception{
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		System.out.println("Start Test: Create Loa");
		CreateLOA loa = new CreateLOA();
		String returnedString = loa.create(driver, "covered");
		String[] arrString = returnedString.split(",");
		loa_number = arrString[1];
		pin = arrString[0];
		System.out.println("Loa Number: "+loa_number);
		System.out.println("End Test: Create Loa\n");
	}
	@Test
	public void c_clear_search_loa() throws Exception{
		System.out.println("Start Test: CLEAR in SEARCH LOA");
		SearchFunctionLoa search_loa = new SearchFunctionLoa();
		search_loa.clear(driver);
		System.out.println("End Test: CLEAR in SEARCH LOA\n");
	}
	@Test
	public void d_search_draft_loa() throws Exception{
		System.out.println("Start Test: SEARCH DRAFT LOA");
		SearchFunctionLoa search_loa = new SearchFunctionLoa();
		search_loa.search(driver, "number", loa_number);
		System.out.println("End Test: SEARCH DRAFT LOA\n");
	}
	@Test
	public void e_select_draft_loa() throws Exception{
		System.out.println("Start Test: SELECT DRAFT LOA");
		SearchFunctionLoa search_loa = new SearchFunctionLoa();
		String status = search_loa.select(driver, "edit");
		if(status.equals("New")){
			System.out.println("Status of Draft LOA: CORRECT");
		}else{
			System.out.println("Status of Draft LOA: INCORRECT");
		}
		System.out.println("End Test: SELECT DRAFT LOA\n");
	}
	@Test
	public void f_generate_final_loa() throws Exception{
		System.out.println("Start Test: GENERATE FINAL LOA");
		Miscellaneous m = new Miscellaneous();
		m.loa_buttons(driver, "final", "");
		System.out.println("LOA is Finalized for Review");
		System.out.println("End Test: GENERATE FINAL LOA\n");
	}
	@Test
	public void g_search_final_loa() throws Exception{
		System.out.println("Start Test: SEARCH PENDING LOA");
		SearchFunctionLoa search_loa = new SearchFunctionLoa();
		search_loa.search(driver, "number", loa_number);
		System.out.println("End Test: SEARCH PENDING LOA\n");
	}
	@Test
	public void h_select_final_loa() throws Exception{
		System.out.println("Start Test: SELECT FINAL LOA");
		SearchFunctionLoa search_loa = new SearchFunctionLoa();
		String status = search_loa.select(driver, "review");
		if(status.equals("Pending")){
			System.out.println("Status of Final LOA: CORRECT");
		}else{
			System.out.println("Status of Final LOA: INCORRECT");
		}
		System.out.println("End Test: SELECT FINAL LOA\n");
	}
	@Test
	public void i_disapprove_loa() throws Exception{
		System.out.println("Start Test: DISAPPROVE FINAL LOA");
		Miscellaneous m = new Miscellaneous();
		m.loa_buttons(driver, "disapprove", "");
		System.out.println("Loa Review: DISAPPROVED!");
		System.out.println("End Test: DISAPPROVE FINAL LOA\n");
	}
	@Test
	public void j_search_disapproved_loa() throws Exception{
		System.out.println("Start Test: SEARCH DISAPPROVED LOA");
		SearchFunctionLoa search_loa = new SearchFunctionLoa();
		search_loa.search(driver, "number", loa_number);
		System.out.println("End Test: SEARCH DISAPPROVED LOA\n");
	}
	@Test
	public void k_select_disapprove_loa() throws Exception{
		System.out.println("Start Test: SELECT DISAPPROVED LOA");
		SearchFunctionLoa search_loa = new SearchFunctionLoa();
		String status = search_loa.select(driver, "view");
		if(status.equals("Disapproved")){
			System.out.println("Status of Disapproved LOA: CORRECT");
		}else{
			System.out.println("Status of Disapproved LOA: INCORRECT");
		}
		System.out.println("End Test: SELECT DISAPPROVED LOA\n");
	}
	@Test
	public void l_logout() throws Exception{
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		System.out.println("Start Test: LOGOUT");
		Logout out = new Logout();
		out.app(driver);
		System.out.println("End Test: LOGOUT\n");
	}
}
